﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}

	protected void btnOutput_Click(object sender, EventArgs e)
	{
		Output(lbSample1, lblOutput1);
		Output(lbSample2, lblOutput2);
		Output(lbSample3, lblOutput3);
		Output(lbSample4, lblOutput4);
		Output(lbSample5a, lblOutput5a);
		Output(lbSample5b, lblOutput5b);
		Output(lbSample6, lblOutput6);
	}

	private void Output(ListBox listBox, Label output)
	{
		List<String> selectedOptions = new List<String>();
		output.Text = "<i>Selected options:</i> ";

		foreach (ListItem li in listBox.Items)
		{
			if (li.Selected)
			{
				selectedOptions.Add(li.Text);
			}
		}

		output.Text += String.Join(", ", selectedOptions.ToArray());
		output.Visible = true;
	}
}
